package com.zhuangjie.base.entity;

import java.time.LocalDate;
import java.util.Objects;

/**
 * 日期范围
 *
 * @author zhuangjie
 * @date 2023/11/16
 */
public class LocalDateRange {
    public LocalDate startDate;
    public LocalDate endDate;

    /**
     * 看指定localDate是否在this的LocalDateRange的范围内
     *
     * @param localDate 当地日期
     * @return {@link Boolean}
     */
    public Boolean in(LocalDate localDate) {
        return (localDate.isEqual(startDate) || localDate.isAfter(startDate))
                && (localDate.isEqual(endDate) || localDate.isBefore(endDate));
    }

    /**
     * 是否为绝对范围
     *
     * @return {@link Boolean}
     */
    public Boolean isAbsoluteRange() {
        return startDate != null && endDate != null;
    }

    public LocalDateRange() {}
    public LocalDateRange(LocalDate startDate,LocalDate endDate) {
        this.startDate = startDate;
        this.endDate = endDate;
    }

    public LocalDate getStartDate() {
        return startDate;
    }

    public void setStartDate(LocalDate startDate) {
        this.startDate = startDate;
    }

    public LocalDate getEndDate() {
        return endDate;
    }

    public void setEndDate(LocalDate endDate) {
        this.endDate = endDate;
    }

    @Override
    public int hashCode() {
        return Objects.hash(startDate, endDate);
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null || getClass() != obj.getClass()) return false;

        LocalDateRange other = (LocalDateRange) obj;

        return Objects.equals(startDate, other.startDate) && Objects.equals(endDate, other.endDate);
    }

}
